package day0920_1;

import java.util.*;

class Student{
    String stuNo;
    String name;
    int age;


    public String toString() {
        return "Student{" +
                "stuNo='" + stuNo + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Student() {
    }

    public Student(String stuNo, String name, int age) {
        this.stuNo = stuNo;
        this.name = name;
        this.age = age;
    }
}






public class T3 {
    public static void main(String[] args) {
        Map<String,Student> map = new HashMap();

        Student  liuChao=new Student("big1_1001","刘超",23);
        map.put(liuChao.stuNo,   liuChao);//学号key，  Student对象value


        Student  lc=map.remove("big1_1001");
        //根据key删除key-value,返回被删除的value(返回被删除的Student对象刘超)
        System.out.println("lc = " + lc);


        Student  baoJX=new Student("big1_1002","鲍嘉欣",23);
        map.put(baoJX.stuNo,    baoJX);//学号key，  Student对象value












        Collection<Student> ss=map.values();//也是一个set集合  元素是
        Iterator<Student> it=ss.iterator();//A.
        while(it.hasNext()){//B.
            Student s=it.next();//C.
        }





        Set<Map.Entry<String,Student>> s=map.entrySet();  //集合中所有的键值对
        //Map.Entry  map集合的每个元素是一个entry对象(键值对对象)
        //       <String,Student>  键值对的左边是字符串，右边是学生对象
        Iterator<Map.Entry<String,Student>> ite=s.iterator();//A.
        while( ite.hasNext() ){//B.hasNext判断迭代器指针的下一位是否有元素
            Map.Entry<String,Student> e =ite.next();//使用迭代器的  获取指针的下一位是否有元素
            System.out.println("e.getKey() = " + e.getKey());
            System.out.println("e.getValue() = " + e.getValue());
        }//Entry：键值对儿








        boolean isC=map.containsKey("big1_1001");//isContainsKey();
        boolean isV=map.containsValue(liuChao);//isContainsKey();
        Student s1=map.get(liuChao.stuNo);//根据key从map中获取value


    }
}









